package com.hsc.yalebao.face;

import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.text.SpannableString;
import android.text.style.ImageSpan;
import com.hsc.yalebao.weight.LogUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FaceUtil
{
  public static final String DELE_IMAGE_NAME = "face_delete";
  public static final String DELE_KEY = "[DELETE_ICON]";

  public static void dealExpression(Context paramContext, SpannableString paramSpannableString, Pattern paramPattern, int paramInt)
    throws SecurityException, IllegalArgumentException, IllegalAccessException
  {
    Matcher localMatcher = paramPattern.matcher(paramSpannableString);
    if (!localMatcher.find());
    while (true)
    {
      return;
      String str1 = localMatcher.group();
      if (localMatcher.start() < paramInt)
        break;
      String str2 = getFacePath("face", getFaceImageName(paramContext, str1));
      try
      {
        Bitmap localBitmap2 = BitmapFactory.decodeStream(paramContext.getAssets().open(str2));
        localBitmap1 = localBitmap2;
        BitmapDrawable localBitmapDrawable = new BitmapDrawable(null, localBitmap1);
        int i = localBitmapDrawable.getIntrinsicWidth();
        f = i / 10;
        if (f <= 1.0F)
        {
          f = 4.0F;
          LogUtils.e("dealExpression", "drawableLevel:" + f);
          localBitmapDrawable.setBounds(0, 0, (int)(f * i), (int)(f * i));
          ImageSpan localImageSpan = new ImageSpan(localBitmapDrawable);
          int j = localMatcher.start() + str1.length();
          paramSpannableString.setSpan(localImageSpan, localMatcher.start(), j, 33);
          if (j >= paramSpannableString.length())
            continue;
          dealExpression(paramContext, paramSpannableString, paramPattern, j);
          return;
        }
      }
      catch (IOException localIOException)
      {
        while (true)
        {
          float f;
          localIOException.printStackTrace();
          Bitmap localBitmap1 = null;
          continue;
          if (f <= 2.0F)
            f = 3.0F;
          else if (f <= 3.0F)
            f = 1.5F;
          else if (f <= 4.0F)
            f = 0.8F;
          else if (f <= 5.0F)
            f = 0.6F;
          else if (f <= 6.0F)
            f = 0.4F;
        }
      }
    }
  }

  public static SpannableString getExpressionString(Context paramContext, String paramString)
  {
    SpannableString localSpannableString = new SpannableString(paramString);
    Pattern localPattern = Pattern.compile("\\[[\\s\\S]{1,3}\\]", 2);
    try
    {
      dealExpression(paramContext, localSpannableString, localPattern, 0);
      return localSpannableString;
    }
    catch (Exception localException)
    {
      LogUtils.e("dealExpression", localException.getMessage());
    }
    return new SpannableString("");
  }

  public static String getFaceImageName(Context paramContext, String paramString)
  {
    return (String)getFaceMap(paramContext).get(paramString);
  }

  public static List<FaceBean> getFaceList(Context paramContext, String paramString)
  {
    ArrayList localArrayList = new ArrayList();
    try
    {
      BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(paramContext.getResources().getAssets().open(paramString), "UTF-8"));
      while (true)
      {
        String str = localBufferedReader.readLine();
        if (str == null)
          return localArrayList;
        String[] arrayOfString = str.split("===");
        FaceBean localFaceBean = new FaceBean();
        localFaceBean.setKey(arrayOfString[0]);
        localFaceBean.setImageName(arrayOfString[1]);
        localArrayList.add(localFaceBean);
      }
    }
    catch (IOException localIOException)
    {
      localIOException = localIOException;
      localIOException.printStackTrace();
      return localArrayList;
    }
    finally
    {
    }
    return localArrayList;
  }

  public static Map<String, String> getFaceMap(Context paramContext)
  {
    HashMap localHashMap = new HashMap();
    try
    {
      BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(paramContext.getResources().getAssets().open("face_default_string"), "UTF-8"));
      while (true)
      {
        String str = localBufferedReader.readLine();
        if (str == null)
          return localHashMap;
        String[] arrayOfString = str.split("===");
        localHashMap.put(arrayOfString[0], arrayOfString[1]);
      }
    }
    catch (IOException localIOException)
    {
      localIOException = localIOException;
      localIOException.printStackTrace();
      return localHashMap;
    }
    finally
    {
    }
    return localHashMap;
  }

  public static String getFacePath(String paramString1, String paramString2)
  {
    return paramString1 + File.separator + paramString2 + ".png";
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.hsc.yalebao.face.FaceUtil
 * JD-Core Version:    0.6.2
 */